package pl.lodz.p.browarex.dao;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import pl.lodz.p.browarex.base.BaseCrudDao;
import pl.lodz.p.browarex.model.Customer;

@Repository
public class CustomerDAO extends BaseCrudDao<Customer, Long> {

	public CustomerDAO(Class<Customer> type) {
		super(type);
	}

	public CustomerDAO() {
		super(Customer.class);
	}

	public Customer getByUsername(String username) {
		Criteria criteria = getSession().createCriteria(type);
		criteria.add(Restrictions.eq("username", username));
		return (Customer) criteria.uniqueResult();
	}

	public Customer getByCustomerID(String customerID) {
		Criteria criteria = getSession().createCriteria(type);
		criteria.add(Restrictions.eq("customerID", customerID));
		return (Customer) criteria.uniqueResult();
	}

}
